from django.urls import path, include

from saas_main.views.api import account_api_view, project_api_view, project_api_detail_view
from saas_main.views.page import page_account, page_home, page_project

app_name = 'saas_main'

urlpatterns = [
    # 首页路由
    path('index/', page_home.index, name='index'),
    # 测试路由
    path('show/', page_home.show_test, name='show'),
    path('show/drf/', page_home.Test.as_view(), name='showdrf'),

    # 价格和支付
    path('price/', page_home.price, name='price'),
    path('price/order/', page_home.order, name='order'),
    path('price/orderlist/', page_home.order_list, name='orderlist'),
    path('api/payment/', account_api_view.PaymentApiView.as_view(), name='api_payment'),
    path('api/result/', account_api_view.PaymentResultApiView.as_view(), name='api_payment_result'),

    # 注册相关路由
    path('register/', page_account.register, name='register'),
    path('api/register/', account_api_view.RegisterApiView.as_view(), name='api_register'),
    path('api/code/', account_api_view.GetRegisterCode.as_view(), name='api_code'),

    # 登录相关路由
    path('login/', page_account.login, name='login'),
    path('login/verify/code/', page_account.login_code, name='login_code'),
    path('api/login/', account_api_view.LoginApiView.as_view(), name='api_login'),
    path('logout/', account_api_view.LoginApiView.as_view(), name='api_logout'),

    # 项目相关路由
    path('project/', page_project.project_list, name='project'),
    path('api/project/', project_api_view.ProjectApiView.as_view(), name='api_project'),
    path('api/project/<int:project>', project_api_view.ProjectDetailApiView.as_view(), name='api_detail_project'),

    # 星标项目
    path('api/project/star/', project_api_view.ProjectStarAPIView.as_view(), name='api_project_star'),

    # 邀请结果页面
    path('invite/', page_project.project_invite_page, name='invite_code'),

    # 项目具体页面
    path('manage/<int:project>/', include([
        # 看板
        path('dashboard/', page_project.project_dashboard, name='dashboard'),
        path('dashboard/charts/', project_api_detail_view.ProjectDashboard.as_view(), name='api_dashboard_chart'),

        # issue
        path('issues/', page_project.project_issues, name='issues'),
        path('issues/detail/<int:issue_id>', page_project.project_issues_detail, name='issues_detail'),

        # 统计
        path('statistics/', page_project.project_statistics, name='statistics'),
        path('statistics/charts/', project_api_detail_view.ProjectStatistics.as_view(), name='api_statistics_chart'),

        # wiki
        path('wiki/', page_project.project_wiki, name='wiki'),
        path('wiki/<int:wiki_id>', page_project.project_wiki, name='wiki_show'),
        path('wiki/add/', page_project.project_wiki_add, name='wiki_add'),
        path('wiki/edit/<int:wiki_id>', page_project.project_wiki_add, name='wiki_edit'),
        path('wiki/upload/', project_api_detail_view.ProjectWikiUpload.as_view(), name='api_wiki_upload'),

        # 文件管理
        path('file/', page_project.project_file, name='file'),
        path('api/file/credential/', project_api_detail_view.ProjectFileCredential.as_view(),
             name='api_file_credential'),
        path('api/file/check', project_api_detail_view.ProjectFileSizeCheck.as_view(),
             name='api_file_check'),

        # 配置
        path('setting/', page_project.project_setting, name='setting'),
        path('setting/delete/', page_project.project_setting_delete, name='setting_delete'),

        # 构建
        path('cases/', page_project.project_cases, name='cases'),
        path('api/cases/', project_api_detail_view.ProjectCases.as_view(), name='api_cases'),

    ]))
]

from rest_framework import routers

router = routers.SimpleRouter()
router.register('api/wiki', project_api_detail_view.ProjectWikiViewSet, basename='wiki')
router.register('api/file', project_api_detail_view.ProjectFileViewSet, basename='file')
router.register('api/issue', project_api_detail_view.ProjectIssueViewSet, basename='issue')
router.register('api/issuereply', project_api_detail_view.ProjectIssueReplyViewSet, basename='reply')
router.register('api/invite/code', project_api_detail_view.ProjectInviteViewSet, basename='invite')

urlpatterns += router.urls
